﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Util
{
    /// <summary>
    /// Pairs two elements
    /// 
    /// Original code obtained by
    /// http://stackoverflow.com/questions/521171/a-java-collection-of-value
    /// -pairs-tuples
    /// 
    /// @author John Salatas <jsalatas@users.sourceforge.net>
    /// </summary>
    public class Pair<L, R>
    {

        // The left element
        private L left;

        // The right element
        private R right;

        /**
        /// Constructor specifying the left and right elements of the Pair.
         */
        public Pair(L left, R right)
        {
            this.left = left;
            this.right = right;
        }

        /**
        /// Set the left element of the Pair
         */
        public void setLeft(L left)
        {
            this.left = left;
        }

        /**
        /// Set the right element of the Pair
         */
        public void setRight(R right)
        {
            this.right = right;
        }

        /**
        /// Get the left element of the Pair
         */
        public L getLeft()
        {
            return left;
        }

        /**
        /// Get the right element of the Pair
         */
        public R getRight()
        {
            return right;
        }

        public int hashCode()
        {
            int prime = 31;
            int result = 1;
            result = prime* result + left.GetHashCode();
            result = prime* result + right.GetHashCode();
            return result;
        }

        override
        public Boolean Equals(Object obj) 
        {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            Pair<L,R> other = (Pair<L,R>) obj;
            if (!left.Equals(other.left))
                return false;
            if (!right.Equals(other.right))
                return false;
            return true;
        }

        /*
        /// (non-Javadoc)
        /// 
        /// @see java.lang.Object#toString()
         */
        override
        public String ToString()
        {
            return "(" + left + ", " + right + ")";
        }
    }
}
